package com.chenchao.javaabstract;

/**
 * @encoding : UTF-8
 * @Time : 2020/11/10 15:02
 * @Author : Chen Chao
 * @File : javaSE.com.chenchao.javaabstract.Abstractgraph.java
 * @Software : IntelliJ IDEA
 * @since : 1.8
 */
public abstract class AbstarctGraph {
    public static void main(String[] args) {
        AbstarctGraph a1=new Rectangle(3,4);
        AbstarctGraph a2=new Circle(3);
        System.out.println(a1.getArea());
        System.out.println(a2.getArea());
    }

    /**
     * 求图形面积
     * @return 返回图形面积
     */
    public abstract double getArea();

}
class Circle extends AbstarctGraph{
    private double r;

    public Circle() {
    }

    public Circle(double r) {
        this.r = r;
    }

    @Override
    public double getArea() {
        return Math.PI*r*r;
    }
}
class Rectangle extends AbstarctGraph{
    private double width;
    private double height;

    public Rectangle() {
    }

    public Rectangle(double width, double height) {
        this.width = width;
        this.height = height;
    }

    @Override
    public double getArea() {
        return width*height;
    }
}